﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace BMUpload
{
    /// <summary>
    /// 解析返回的XML
    /// </summary>
    public  class analysisRV
    {
        private string xml;
        private string fhz;
        private string msg;
        private string errcode;
        private string sessionid;// SESSIONID;

        public string XML
        {
            //get { return xml; }
            set { xml = value; }
        }

        public string FHZ { get { return fhz; } }

        public string MSG { get { return msg; } }

        public string ERRCode { get { return errcode; } }

        public string SESSIONID { get { return sessionid; } }

        public analysisRV()
        { }

        public analysisRV(string rxml)
            : base()
        { xml = rxml; }

        /// <summary>
        /// 处理返回的XML
        /// </summary>
        /// <returns></returns>
        public bool Deal()
        {
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(xml);
                //获取bookshop节点的所有子节点 
                XmlNodeList nodeList = xmlDoc.SelectSingleNode("hnisi/body/params").ChildNodes;// xmlDoc.SelectSingleNode("hnisi").ChildNodes;

                if (nodeList != null)
                {
                    fhz = nodeList.Item(0).Attributes.GetNamedItem("val").Value;

                    errcode = nodeList.Item(1).Attributes.GetNamedItem("key").Value;

                    msg = nodeList.Item(1).Attributes.GetNamedItem("val").Value;

                    if (nodeList.Item(2) != null)
                    {
                        sessionid = nodeList.Item(2).Attributes.GetNamedItem("val").Value;
                    }
                }
                return true;
            }
            catch (XmlException)
            {
                return false;
            }
        }

    }
}
